﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Com.AAS.Toolbox.DataMirror.Setting
{
    public partial class SettingForm : Form
    {
        public SettingForm()
        {
            InitializeComponent();

            this.tabControl1.TabPages.Clear();
            this.Load += SettingGUI_Load;
        }

        void SettingGUI_Load(object sender, EventArgs e)
        {
            this.tabControl1.TabPages.Add(createNewPage(false));
            this.tabControl1.TabPages.Insert(this.tabControl1.TabPages.Count - 1, createNewPage());
            this.tabControl1.SelectedIndex = 0;
        }

        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            TabPage page = this.tabControl1.SelectedTab; ;
            if (page != null && "+".Equals(page.Text.Trim()))
                this.tabControl1.TabPages.Insert(this.tabControl1.TabPages.Count - 1, createNewPage());
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.tabControl1.SelectedIndex == this.tabControl1.TabPages.Count - 1)
            {
                this.tabControl1.SelectedIndex = this.tabControl1.TabPages.Count - 2;
            }
        }

        private TabPage createNewPage(bool hasSettingUC = true)
        {
            if (!hasSettingUC)
            {
                TabPage page = new TabPage() { Text = "  +  " };
                return page;
            }
            else
            {
                MonitorSettingUC uc = new MonitorSettingUC() { Dock = DockStyle.Fill };
                TabPage page = new TabPage() { Text = "Config(" + (this.tabControl1.TabPages.Count) + ")" };
                page.Controls.Add(uc);
                return page;
            }

        }
    }
}
